package demo3;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Map<String , Integer> maps = new HashMap<>();
        maps.put( "iphoneX",10);
        maps.put("娃娃",31);
        maps.put("iphoneX",100); //Hap集合后面重复的键对应的元素会覆盖前面重复的整个元素!
        maps.put( "huawei" , 1000);
        maps.put("生活用品",10);maps.put("手表",10);
        Set<String> keys = maps.keySet();
        for (String key : keys) {
            Integer value = maps.get(key);
            System.out.println(key+"=====>"+value);
        }


        System.out.println("----------------------------------------------------");

        //把map集合转换为set集合
        Set<Map.Entry<String, Integer>> entries = maps.entrySet();
        //开始遍历
        for (Map.Entry<String, Integer> entry : entries) {
            String key = entry.getKey();
            Integer value = entry.getValue();
            System.out.println(key+"=======>"+value);
        }

        System.out.println("----------------------------------------------------");

        maps.forEach((k,v)->{
            System.out.println(k+"==========>"+v);
        });
    }
}
